//
//  ShellNetworkCalculateView.m
//  ShellWallert
//
//  Created by lvzhao on 2019/10/3.
//  Copyright © 2019 VV. All rights reserved.
//

#import "ShellNetworkCalculateView.h"
#import "ShellNetworkCalculateViewModel.h"
#import "ShellCalculateChartView.h"

@interface ShellNetworkCalculateView()

@property (nonatomic,strong) ShellNetworkCalculateViewModel *viewModel;

@property (nonatomic,strong) ShellCalculateChartView *chartView;

@end

@implementation ShellNetworkCalculateView

- (instancetype)initViewModel:(LZBaseViewModel *)viewModel
{
    self = [super init];
    if (self) {
        self.viewModel = (ShellNetworkCalculateViewModel *)viewModel;
        [self setupView];
    }
    return self;
}

#pragma mark - setupView
- (void)setupView{
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.showsVerticalScrollIndicator = NO;
    [self addSubview:scrollView];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.bottom.mas_equalTo(0);
    }];
    
    //内容
    UIView *contentView = [[UIView alloc] init];
    [scrollView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.and.right.equalTo(scrollView).with.insets(UIEdgeInsetsZero);
        make.width.equalTo(scrollView);
    }];
    
    
    [contentView addSubview:self.chartView];
    [self.chartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(510);
    }];
    
    UILabel *titleLab = [UILabel lz_labelWithText:LZLocalizedString(@"全网算力说明") fontSize:k_textFont(15) color:UIColorHex(0xFFFFFF)];
    
    CGFloat titleHeight = [titleLab.text lz_textHeightWithFontSize:titleLab.font withMaxWidth:K_SCREENWIDTH - 30];
    [self addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.chartView.mas_bottom);
        make.width.mas_equalTo(K_SCREENWIDTH - 30);
        make.height.mas_equalTo(titleHeight);
    }];

    
    UILabel *messageLabel = [UILabel lz_labelWithText:LZLocalizedString(@"") fontSize:k_textFont(13) color:UIColorHex(0x678DA8)];
    CGFloat messageHeight = [messageLabel.text lz_textHeightWithFontSize:messageLabel.font withMaxWidth:K_SCREENWIDTH - 30];
    [self addSubview:messageLabel];
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(titleLab.mas_bottom).mas_offset(10);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(messageHeight);
    }];
    
    
    [contentView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(messageLabel.mas_bottom).mas_offset(34);
    }];
    
    @weakify(self);
    [self.viewModel.reloadSubject subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        messageLabel.text = self.viewModel.descText;
        CGFloat messageHeight = [messageLabel.text lz_textHeightWithFontSize:messageLabel.font withMaxWidth:K_SCREENWIDTH - 30];

        [messageLabel mas_updateConstraints:^(MASConstraintMaker *make) {
               make.height.mas_equalTo(messageHeight);
        }];
    }];
    
    
    
    
    
    
    [self.viewModel queryNetworkHashRateList];
}

#pragma mark - get && set
- (ShellCalculateChartView *)chartView{
    if (!_chartView) {
        _chartView = [[ShellCalculateChartView alloc] initViewModel:self.viewModel];
    }
    return _chartView;
    
}

@end
